package com.naodong.shenluntiku.mvp.model.bean;

import net.orange_box.storebox.annotations.method.ClearMethod;
import net.orange_box.storebox.annotations.method.KeyByString;
import net.orange_box.storebox.annotations.method.TypeAdapter;

import java.io.Serializable;

/**
 * Created by hujie on 17/5/8.
 */

public class Token implements Serializable {
    private String accessToken;
    private String refreshToken;
    private long expiresIn;
    private long loginTn;

    public void setLoginTn(long loginTn) {
        this.loginTn = loginTn;
    }

    public String getRefreshToken() {
        return refreshToken;
    }

    public void setRefreshToken(String refreshToken) {
        this.refreshToken = refreshToken;
    }

    public long getExpiresIn() {
        return expiresIn;
    }

    public void setExpiresIn(long expiresIn) {
        this.expiresIn = expiresIn;
    }

    /**
     * 是否有效
     * @return
     */
    public boolean isExpires() {
        if (System.currentTimeMillis() - loginTn < expiresIn * 1000) {
            return true;
        }
        return false;
    }


    public String getAccessToken() {
        return accessToken;
    }

    public void setAccessToken(String accessToken) {
        this.accessToken = accessToken;
    }


    public interface TokenPerferences {

        @KeyByString("key_token")
        @TypeAdapter(TokenTypeAdapter.class)
        void saveToken(Token token);

        @KeyByString("key_token")
        @TypeAdapter(TokenTypeAdapter.class)
        Token getToken();

        @ClearMethod
        void clear();
    }


}

